package graduationorder.graduationorder.controller;

import graduationorder.graduationorder.domain.User;
import graduationorder.graduationorder.error.BusinessException;
import graduationorder.graduationorder.handler.GlobalExceptionHandler;
import graduationorder.graduationorder.result.CommonReturnType;
import graduationorder.graduationorder.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.SqlReturnType;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author Mzk
 * @version 1.0
 * @description: 用户相关接口
 * @date 2024/8/3 下午 12:41
 */
@RestController
@RequestMapping("/api")
public class UserController extends GlobalExceptionHandler {

    @Autowired
    private UserService userService;
    // 登录
    @PostMapping("/login")
    public CommonReturnType login(String userName, String password) throws BusinessException {
        return userService.login(userName, password);
    }
    //新增用户
    @PostMapping("/users")
    public CommonReturnType increaseUser(User addUser, @RequestHeader("Authorization") String token) throws BusinessException {
        return userService.increaseUser(addUser, token);
    }
    //获取用户信息
    @GetMapping("/queryUser")
    public CommonReturnType queryUser(String userName, String employeeId, @RequestHeader("Authorization") String token) throws BusinessException {
        return userService.queryUser(userName, employeeId, token);
    }

    @PostMapping("/update")
    public CommonReturnType updateUser(User updateUser, @RequestHeader("Authorization") String token) throws BusinessException {
        return userService.updateUser(updateUser,token);
    }

    @PostMapping("/delete")
    public CommonReturnType deleteUser(Integer userId, @RequestHeader("Authorization") String token) throws BusinessException {
        return userService.deleteUser(userId, token);
    }

    @PostMapping("/modifyPwd")
    public CommonReturnType modifyPassword(String employeeId, String password, String newPassword) throws BusinessException {
        return userService.modifyPassword(employeeId, password, newPassword);
    }
}
